package handlers

import (
	"context"
	"douyin_mini/cmd/api/rpc"
	"douyin_mini/kitex_gen/user"
	"douyin_mini/pkg/constants"
	"douyin_mini/pkg/errno"
	"fmt"
	"github.com/cloudwego/hertz/pkg/app"
	"strconv"
)

// GetUserInfo 获取用户信息
func GetUserInfo(ctx context.Context, c *app.RequestContext) {

	toUserIdStr := c.Query(constants.UserID)
	//for test
	fmt.Println(toUserIdStr)

	toUserId, err := strconv.ParseInt(toUserIdStr, 10, 64)
	if err != nil {
		SendResponse(c, errno.ConvertErr(err), nil)
		return
	}
	UserIds := make([]int64, 1)
	UserIds[0] = toUserId
	info, err := rpc.GetUserInfo(ctx, &user.UserInfoRequest{UserIds: UserIds})
	if err != nil {
		SendResponse(c, errno.ServiceErr, nil)
		return
	}
	SendResponse(c, errno.Success, info)
}
